<?php
//  This example script extends what was explained in the previous one by demonstrating more features







// Before running, check the paths in the demo_initialization file
include('demo_initialization.php');


// This will demonstrate use of a custom submission detection function
function my_custom_tipoff_function( ){
  if( count($_POST) ){ return 'post'; };
  else return false;
}



$imp = new Imp($smarty, 'my_custom_tipoff_function', null);
$imp->configure('behavior_presumed_valid', false); // Validation on this form will work the opposite of normal.  Instead of being presumed valid until an invalidator is fired, this form will be considered invalid until a validator claims otherwise.  Also, invalidators will now trump validators when a conflict arises for one requirement



// this will demonstrate the use of custom validation funcitons
function age_discriminator( $miles ){
  if( $miles === 'many' ){ return true ; }
  else                   { return false; }
}

$imp->invalidator('model_exists', 'longer_than' , array(imp_oot('model'), 5));
$imp->invalidator('must_agree'  , 'empty'       , array(imp_oot('agree')   ));
// Since those validation functions were not valid in the global namespace, they automatically searched the library of functions in the imp namespace


$imp->invalidator('too_old', 'age_discriminator', array(imp_oot('miles')));



// here, i'll check if the form was submitted
if( $imp->submitted() ){
  echo'YOU HAVE SUBMITTED THIS FORM...<BR/>';
  if( $imp->validate() ){
    echo 'AND IT WAS VALID!';
    exit();
  }
  ECHO 'BUT THERE WERE ERRORS:<BR/>';
}



$smarty->display('simple_form.tpl');

?>
